<template>
  <el-card class="content">
    <el-row>
      <el-col :span="5">
        <span style="fontsize: 16px">隐患排查点：</span>
        <el-input
          size="mini"
          style="width: 200px"
          placeholder="请输入查询内容"
          v-model="query.investigationPoint"
          clearable
        >
        </el-input>
      </el-col>
      <el-col :span="6">
        <el-button
          class="black-button"
          type="primary"
          size="small"
          @click="getSearch"
          >查询</el-button
        >
      </el-col>
    </el-row>
    <el-table
      :data="preventionList"
      stripe
      size="small"
      :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }"
      class="el-table-box"
    >
      <el-table-column
        label="排查点"
        prop="investigationPoint"
        align="center"
        width="150px"
      >
      </el-table-column>
      <el-table-column
        label="排查隐患"
        prop="hiddenDanger"
        align="center"
      ></el-table-column>
      <el-table-column
        label="智能决策"
        prop="intelligentDecision"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="图片"
        prop="intelligentDecisionImage"
        align="center"
      >
        <template slot-scope="scope">
          <div @click="srcDate(scope.row)">
            <el-image
              v-if="srcLenght !== 1"
              :src="imgUrl + scope.row.intelligentDecisionImage.split(',')[0]"
              class="bigIntelligent"
              :preview-src-list="srcBigList"
            ></el-image>
            <el-image
              v-if="srcLenght == 1"
              :src="imgUrl + scope.row.intelligentDecisionImage"
              class="bigIntelligent"
              :preview-src-list="srcBigList"
            ></el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="上报人"
        prop="reportUserName"
        align="center"
      ></el-table-column>
      <el-table-column
        label="上报时间"
        prop="createTime"
        align="center"
      ></el-table-column>
      <el-table-column label="处理人" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.handleType == 0">{{
            scope.row.updateUserName
          }}</span>
          <span v-if="scope.row.handleType == 2">{{
            scope.row.updateUserName
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理情况" align="center">
        <template slot-scope="scope">
          <el-button type="danger" size="small" v-if="scope.row.status == 0"
            >未处理</el-button
          >
          <el-button type="success" size="small" v-if="scope.row.status == 1"
            >已处理</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="处理图片" prop="handleType" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.status == 0"></div>
          <div v-if="scope.row.status == 1">

            <div
              v-if="scope.row.handleType == 0"
              @click="handleDate(scope.row)"
            >
              <el-image
                v-if="srcLenght !== 1"
                :src="imgUrl + scope.row.handleImage.split(',')[0]"
                class="bigIntelligent"
                :preview-src-list="handelSrcBigList"
              ></el-image>
            </div>
            <div v-if="scope.row.handleType == 2">
              <el-image
                v-if="srcLenght == 1"
                :src="imgUrl + scope.row.turnHandleImage"
                class="bigIntelligent"
                :preview-src-list="handelSrcBigList"
              ></el-image>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="处理时间"
        prop="updateTime"
        align="center"
      ></el-table-column>
      <el-table-column label="备注" prop="handleStatus" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.handleType == 0">{{
            scope.row.handleStatus
          }}</span>
          <span v-if="scope.row.handleType == 2">{{
            scope.row.turnHandleStatus
          }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-row type="flex" justify="end">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.page"
        :page-sizes="[10, 15]"
        :page-size="query.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-row>
  </el-card>
</template>

<script>
import {
  getPreventionListByPage,
  imgUrl,
} from "../../../api/safety-management-api";
export default {
  name: "HiddenTroubleNvestigationAndManagement",
  data() {
    return {
      query: {
        page: 1,
        pagesize: 10,
        investigationPoint: "",
      },
      total: null,
      imgUrl,
      preventionList: [],
      srcLenght: null,
      // 放大图片
      srcBigList: [],
      handelSrcLenght: null,
      // 放大处理图片
      handelSrcBigList: [],
    };
  },
  created() {
    this.getPreventionListByPage();
  },
  methods: {
    async getPreventionListByPage() {
      const res = await getPreventionListByPage({
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        unitId: sessionStorage.getItem("unitId"),
      });
      console.log(res);
      if (res.resultCode == "200") {
        this.preventionList = res.parameter.list;
        this.total = res.parameter.total;
      } else {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.preventionList = [];
      }
    },
    // 监听 pagesize 改变的事件
    handleSizeChange(val) {
      this.query.pagesize = val;
      this.getPreventionListByPage();
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(val) {
      this.query.page = val;
      this.getPreventionListByPage();
    },
    async getSearch() {
      const res = await getPreventionListByPage({
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        investigationPoint: this.query.investigationPoint,
        unitId: sessionStorage.getItem("unitId"),
      });
      console.log(res);
      if (res.resultCode == "200") {
        this.$message.success({
          message: "成功查询数据",
          offset: 400,
          duration: 1000,
        });
        this.preventionList = res.parameter.list;
        this.total = res.parameter.total;
      } else {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.preventionList = [];
      }
    },
    srcDate(row) {
      this.srcBigList = [];
      if (row.intelligentDecisionImage.indexOf(",") !== -1) {
        var ele = row.intelligentDecisionImage.split(",");
        this.srcLenght = ele.length;
        for (let i = 0; i < ele.length; i++) {
          var e = ele[i];
          this.srcBigList.push(imgUrl + e);
        }
      } else {
        this.srcBigList.push(imgUrl + row.intelligentDecisionImage);
      }
    },
    handleDate(row) {
      this.handelSrcBigList = [];
      if (row.handleType == 0) {
        if (row.handleImage.indexOf(",") !== -1) {
          var ele = row.handleImage.split(",");
          this.handelSrcLenght = ele.length;
          for (let i = 0; i < ele.length; i++) {
            var e = ele[i];
            this.handelSrcBigList.push(imgUrl + e);
          }
        } else {
          this.handelSrcBigList.push(imgUrl + row.handleImage);
        }
      } else if (row.handleType == 2) {
        if (row.turnHandleImage.indexOf(",") !== -1) {
          var ele = row.turnHandleImage.split(",");
          this.handelSrcLenght = ele.length;
          for (let i = 0; i < ele.length; i++) {
            var e = ele[i];
            this.handelSrcBigList.push(imgUrl + e);
          }
        } else {
          this.handelSrcBigList.push(imgUrl + row.turnHandleImage);
        }
      }
    },   
  },
};
</script>

<style scoped>
.content {
  margin-right: 5px;
  height: 87vh;
}
.list {
  height: 83vh;
}
.el-table-box {
  display: block;
  height: 72vh;
  overflow-y: auto;
  margin-top: 10px;
  margin-bottom: 20px;
}
.el-table::before {
  z-index: inherit;
}
.bigIntelligent {
  max-height: 50px;
  max-width: 50px;
  object-fit: contain;
}
.bigImg {
  max-height: 300px;
  max-width: 300px;
  overflow: auto;
}
</style>
